<template>
   <van-icon :name="value===1 ? 'good-job':'good-job-o'"
    :color="value===1 ? '#e5645f':''" 
    @click="onCollect"
   />
</template>

<script>
import {addLike, deleteLike} from '@/api/article'
export default {
  name: 'LikeArticle',
  mixins: [],
  components: {},
  props: {
    value:{
        type:Number,
        required:true
    },
    articleId:{
        type:[String,Number,Object],
        required:true
    }
  },
  data () {
    return {

    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    async onCollect(){
        this.$toast.loading({
            duration:0,
            message:'',
            forbidClick:true
        })
        try{
            let status = -1
            if(this.value ===1){
                await deleteLike(this.articleId)
            }else{
                await addLike(this.articleId)
                status = 1
            }
            this.$emit('input',status)
            this.$toast.success(status ===1 ? '点赞成功':'取消点赞')
        }catch(err){
            console.log(err)
            this.$toast.fail('操作失败，请重试')
        }
    }
  }
}
</script>

<style scoped lang="less">

</style>